Package vg.userInterface.scaling.components

Source Code of vg.userInterface.scaling.components.ZoomBox

package vg.userInterface.scaling.components;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.SwingUtilities;

import vg.core.IGraphView;
import vg.userInterface.swingComponents.ZoomComboBox;

/**
* This class realizes module for zoom.
* @author tzolotuhin
*/
public class ZoomBox {
  // Main components
  private final ZoomComboBox element;
  // Data
  private IGraphView view;
  // Mutex
  private final Object theMutexObject;
  /**
   * Constructor.
   */
  public ZoomBox() {
    // init mutex
    this.theMutexObject = new Object();
    // init components
    this.element = new ZoomComboBox();
    this.element.setToolTipText("Scaling of graph's view");
    this.view = null;
    this.element.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        synchronized (ZoomBox.this.theMutexObject) {
          if (ZoomBox.this.view != null)
            ZoomBox.this.view.setZoom(ZoomBox.this.element.getScale());
        }
      }
    });     
  }
  public JComponent getView() {
    return(this.element.getView());
  }
  /**
   * This method changes current view.
   */
  public void changeView(final IGraphView newView) {
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        synchronized (ZoomBox.this.theMutexObject) {
          ZoomBox.this.view = newView;
          if (ZoomBox.this.view != null) {
            ZoomBox.this.view.SetEnableZoomComboToGraphView(true, ZoomBox.this.element);
            ZoomBox.this.element.enable();
          } else {
            ZoomBox.this.element.disable();
          }
        }
      }
    });
  }
}
TOP

Related Classes of vg.userInterface.scaling.components.ZoomBox

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.